package com.cty;

import com.cty.Repository.MenuRepository;
import com.cty.Repository.UserRepository;
import com.cty.pojo.Menu;
import com.cty.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Arrays;
import java.util.List;

@SpringBootTest(classes = Main.class)
public class testManyToMany {


    @Autowired
    private UserRepository userRepository;

    @Autowired
    private MenuRepository menuRepository;
    // 单向关联
    @Test
    public void test01() {
        Menu menu1 = new Menu();
        menu1.setName("后台管理");
        Menu menu2 = new Menu();
        menu2.setName("前台管理");
        Menu menu3 = new Menu();
        menu3.setName("用户管理");
        List<Menu> menus = Arrays.asList(menu1, menu2, menu3);
        User user = new User();
        user.setUserName("张三");
        user.setPassword("123456");
        user.setMenus(menus);

        userRepository.save(user);
    }
    @Test
    public void test02() {
        Menu menu = new Menu();
        menu.setName("系统管理");

        User user1 = new User();
        user1.setPassword("123456");
        user1.setUserName("李四");
        User user2 = new User();
        user2.setPassword("123456");
        user2.setUserName("王五");
        User user3 = new User();
        user3.setPassword("123456");
        user3.setUserName("赵六");

        List<User> users = Arrays.asList(user1, user2, user3);
        menu.setUsers(users);
        menuRepository.save(menu);
    }
}
